home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8461 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  42 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: razine@aol.com (Razine)
  3. Newsgroups: comp.lang.c
  4. Subject: Calling a Function Twice from a printf statement.
  5. Date: 4 Mar 1996 02:40:57 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4he6q9$6r6@newsbf02.news.aol.com>
  9. Reply-To: razine@aol.com (Razine)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. I am trying to call a function twice from my program on the same printf
  13. line and have run into a small problem.  i was wondering if someone can
  14. explain how to fix it.
  15.  
  16.  
  17. void main(void) {
  18.  
  19.    printf("First Number is %d , the Second s %d \n",num(0),num(1));
  20.  
  21. }
  22.  
  23. int num(int index) {
  24.    int return_number;
  25.    
  26.    switch(index) {
  27.        case 0 : return_number=0;
  28.        case 1 : return_number=1;
  29.                        }
  30.    return(return_number);
  31. }
  32.  
  33.  
  34. Now with this function, the printf line will display 0 for the first one
  35. and garbage for the second one..  I then thought if I made the variable
  36. return_number a static variable it would have fixed it but then when i
  37. made the change the printf line would give me zero for both of them.  Any
  38. ideas?
  39.  
  40. Darrell
  41.  
  42.